<?php
/*********************************************************************************
 * Copyright (C) 2011-2013 X2Engine Inc. All Rights Reserved.
 * 
 * X2Engine Inc.
 * P.O. Box 66752
 * Scotts Valley, California 95067 USA
 * 
 * Company website: http://www.x2engine.com 
 * Community and support website: http://www.x2community.com 
 * 
 * X2Engine Inc. grants you a perpetual, non-exclusive, non-transferable license 
 * to install and use this Software for your internal business purposes.  
 * You shall not modify, distribute, license or sublicense the Software.
 * Title, ownership, and all intellectual property rights in the Software belong 
 * exclusively to X2Engine.
 * 
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
 ********************************************************************************/

/*
Used primarily as a ui container for the X2Chart widget. Also retrieves association id
and association type of model and the date of the first associated action.
 */
class RecordViewChart extends X2Widget {
	public $model;
	public $modelName;
	public $widgetParams = array ();

	public function init() {
		parent::init();
	}

	public function run() {
		if (!isset ($this->model)) return;

		$viewParams = array ();
		foreach ($this->widgetParams as $paramName=>$paramVal) {
			$viewParams[$paramName] = $paramVal;
		}

		if ($this->widgetParams['chartType'] === 'actionHistoryChart') {
			$associationId = $this->model->id;
			$associationType = strtolower ($this->modelName);//Yii::app()->controller->module->id;
            //printR ($associationType);
            /*printR (Yii::app()->controller->module->id);
            printR ($this->modelName);*/
			$viewParams['associationId'] = $associationId;
			$viewParams['associationType'] = $associationType;
			$this->render ('_actionHistoryChart', $viewParams);
		} /* x2prostart */ else if ($this->widgetParams['chartType'] === 'campaignChart') {
			$viewParams['model'] = $this->model;
			$this->render ('_campaignChart', $viewParams);
		} /* x2proend */
	}
}

